package com.atguigu.msm.service.impl;

import com.atguigu.constant.StringPool;
import com.atguigu.msm.service.MsmCacheService;
import com.atguigu.serviceBase.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * 验证码缓存
 * @author Summerday
 */
@Service
public class MsmCacheServiceImpl implements MsmCacheService {

    @Value("${redis.database}")
    private String REDIS_DATABASE;
    @Value("${redis.expire.authCode}")
    private Long REDIS_EXPIRE_AUTH_CODE;
    @Value("${redis.key.authCode}")
    private String REDIS_KEY_AUTH_CODE;

    @Autowired
    private RedisService redisService;

    @Override
    public void setAuthCode(String phone, String authCode) {
        String key = REDIS_DATABASE+ StringPool.COLON+REDIS_KEY_AUTH_CODE+phone;
        redisService.set(key,authCode,REDIS_EXPIRE_AUTH_CODE);
    }

    @Override
    public String getAuthCode(String phone) {
        String key = REDIS_DATABASE+ StringPool.COLON+REDIS_KEY_AUTH_CODE+phone;
        return (String) redisService.get(key);
    }
}
